
import wx
import wx.lib.agw.customtreectrl as CT

class CaseControlPhenotypeList(wx.lib.agw.customtreectrl.CustomTreeCtrl):
    def __init__(self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.DefaultSize, style =CT.TR_DEFAULT_STYLE):

        #wx.Frame.__init__(self, parent, -1, "CustomTreeCtrl Demo")        

        # Create a CustomTreeCtrl instance
        wx.lib.agw.customtreectrl.CustomTreeCtrl.__init__(self, parent, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 
                                                          style=style | wx.TR_HIDE_ROOT) 
                                                          #| wx.TR_LINES_AT_ROOT )#| CT.TR_ROW_LINES)#| wx.TR_TWIST_BUTTONS)  | CT.TR_AUTO_CHECK_PARENT
        #custom_tree.SetIndent(100)
        # Add a root node to it
        self.root = self.AddRoot("The Root Item")            
#        root2 = custom_tree.AddRoot("The Root Item")            

        #self.SetSpacing(100)

        # Create an image list to add icons next to an item
        il = wx.ImageList(20, 20)
        #fldridx     = il.Add(wx.ArtProvider_GetBitmap((wx.ART_FOLDER,      wx.ART_OTHER, 16)))
        #fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN,   wx.ART_OTHER, 16))
        #fileidx     = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, 16))
        #self.snp_icon     = il.Add(wx.Bitmap("images/snp_diagram_icon2_20x35.png"))
        #self.gene_icon = il.Add(wx.Bitmap("images/dna_small_icon.jpg"))
        #self.gene_icon = il.Add(wx.Bitmap("images/gene_icon_vert_45x27.jpg"))
        self.entry_icon = il.Add(wx.Bitmap("images/project_icons/orbs/DarkBlue1_20x20.png"))
        
        #fileidx     = il.Add(wx.Bitmap("images/project_icons/music_16.png"))
        #wx.ImageList.a
        self.SetImageList(il)
        self.SetIndent(0)        
 
        #custom_tree.SetItemImage(root, gene_icon, wx.TreeItemIcon_Normal)
        #custom_tree.SetItemImage(root, gene_icon, wx.TreeItemIcon_Expanded)
        #custom_tree.AutoCheckChild(root, True)
        traits = ["trait1", "trait2", "trait3", "trait4", "trait5"] 
        classes = ["class1", "class2"]
        self.add_items(classes)
        #self.add_phenotypes(traits)
        #self.add_classes(classes)

       
        #self.Bind(CT.EVT_TREE_ITEM_CHECKED, self.OnItemChecked )
        
       
        #for gene in genes:
         #   gene_entry = self.AppendItem(self.root, "%s" % gene, ct_type=1)
            
          #  self.SetItemImage(gene_entry, self.gene_icon, wx.TreeItemIcon_Normal)
          #  self.SetItemImage(gene_entry, self.gene_icon, wx.TreeItemIcon_Expanded)
            #custom_tree.AutoCheckChild(gene_entry, False)
            #custom_tree.Che AutoCheckChild(gene_entry, False)
            #for y in range(5):
            #    snp_entry = self.AppendItem(gene_entry, "rs%s" % y, ct_type=1)
            #    self.SetItemImage(snp_entry, self.snp_icon, wx.TreeItemIcon_Normal)
            #    self.SetItemImage(snp_entry, self.snp_icon, wx.TreeItemIcon_Expanded)
                #custom_tree.CheckItem(snp_entry, True)#SetItemImage(snp_entry, snp_icon, wx.TreeItemIcon_Expanded)
#            custom_tree.AutoToggleChild(gene_entry)
            #custom_tree.CheckChilds(gene_entry, True)
            #custom_tree.
            

#                for z in range(5):
#                    item = custom_tree.AppendItem(last,  "item %d-%s-%d" % (x, chr(ord("a")+y), z))
#                    custom_tree.SetItemImage(item, fileidx, wx.TreeItemIcon_Normal)
#                    custom_tree.SetItemImage(item, fldridx, wx.TreeItemIcon_Selected)
        #custom_tree.Expand(root)
        #self.Bind(wx.EVT_TREE_ITEM_, self.OnGeneChecked)
        #self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnGeneExpanded)
    
    
    def Clear(self):
        self.DeleteChildren(self.root)
    
#    def add_genes(self, gene_names):
#        for gene in gene_names:
#            
#            gene_entry = self.AppendItem(self.root, gene, ct_type=1)
#            
#            self.SetItemImage(gene_entry, self.gene_icon, wx.TreeItemIcon_Normal)
#            self.SetItemImage(gene_entry, self.gene_icon, wx.TreeItemIcon_Expanded)
#            gene_entry.SetBold(True)
#            none_entry = self.AppendItem(gene_entry, "none", ct_type=1)
#    
    
    def add_items(self, items):
        self.Clear()
        for i in items:
            
            entry = self.AppendItem(self.root, i, ct_type=1)
            
            self.SetItemImage(entry, self.entry_icon, wx.TreeItemIcon_Normal)
    
    
    def add_phenotypes(self, phenotypes):
        self.Clear()
        for p in phenotypes:
            
            entry = self.AppendItem(self.root, p, ct_type=1)
            
            self.SetItemImage(entry, self.entry_icon, wx.TreeItemIcon_Normal)
            
            
    
    def add_classes(self, classes):
        self.Clear()
        for c in classes:
            
            entry = self.AppendItem(self.root, c, ct_type=1)
            
            self.SetItemImage(entry, self.entry_icon, wx.TreeItemIcon_Normal)
            #self.SetItemImage(gene_entry, self.gene_icon, wx.TreeItemIcon_Expanded)
            #entry.SetBold(True)
            #none_entry = self.AppendItem(gene_entry, "none", ct_type=1)
            
            #self.SetItemImage(snp_entry, self.snp_icon, wx.TreeItemIcon_Normal)
           
           
    #def OnItemChecked(self, event):
    #    event.Skip() 
#            
#    def add_snps(self, snp_names, parent_gene):
#        #print parent_gene.GetLabel()
#        self.DeleteChildren(parent_gene)
#        for snp in snp_names:
#            snp_entry = self.AppendItem(parent_gene, snp, ct_type=1)
#            self.SetItemImage(snp_entry, self.snp_icon, wx.TreeItemIcon_Normal)
#            self.SetItemImage(snp_entry, self.snp_icon, wx.TreeItemIcon_Expanded)
#            #snp_entry.SetSpacing(100)
#            #snp_entry.SetIndent(100)
#    #    g
        
  #  def gene    
    #def OnGeneChecked(self, event):
    #    print "gene checked"
    #def OnGeneExpanded(self, event):
        #print "expand"
        #event.Skip()
        